<?php 

	include "../inc/dbconn.php";

    // 添加新用户
    $username = $_POST["username"];
    $pwd = md5($_POST["pwd"]);
    $age = $_POST["age"];
    // echo $pwd;

    // 用户名是否存在
    $sql = "select * from user where username='{$username}'";

    $result = $conn->query($sql);

    if ($result->num_rows > 0){
        //用户名重复
        $data["code"] = 3002;
        $data["msg"] = '用户名重复';

    }else{
        // 用户名不重复，添加新用户
        $sql = "insert into user (username,pwd,age) values ('$username','$pwd','$age')";
        if ($conn->query($sql) === TRUE) {
            // 注册成功
            $data['code'] = 3000;
            $data["msg"] = '注册成功';
        } else {
            //服务器错误
            $data['code'] = 3001;
            $data["msg"] = '未知错误';
        }
    }
    echo json_encode($data);
 ?>